package com.cloudcc.mobile.weight;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.cloudcc.mobile.R;

public class DialogUtils {
    public static Dialog showWarn(Context context, String title,
                                  String content, final DialogOnClickListener listener) {
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_warn,
                null);
        final AlertDialog builder = new AlertDialog.Builder(context).create();
        builder.setCancelable(false);
        builder.setView(view);
        TextView dialogTitle = (TextView) view.findViewById(R.id.dialog_title);
        TextView dialogDesc = (TextView) view.findViewById(R.id.dialog_description);
        Button btnPositive = (Button) view.findViewById(R.id.dialog_positive);
        Button btnNegative = (Button) view.findViewById(R.id.dialog_negative);
        dialogTitle.setText(title);
        dialogDesc.setText(content);
        btnNegative.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                listener.onClickNegative(builder);
            }
        });
        btnPositive.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                listener.onClickPositive(builder);
            }
        });
        builder.show();
        return builder;
    }


    public static Dialog showAlert(Context context, String title,
                                   String content, final DialogOnClickListener listener) {
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_alert,
                null);
        final AlertDialog builder = new AlertDialog.Builder(context).create();
        builder.setCancelable(false);

        builder.setView(view);
        TextView dialogTitle = (TextView) view.findViewById(R.id.dialog_title);
        TextView dialogDesc = (TextView) view
                .findViewById(R.id.dialog_description);
        Button btnPositive = (Button) view.findViewById(R.id.dialog_positive);
        dialogTitle.setText(title);
        dialogDesc.setText(content);
        btnPositive.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                listener.onClickNegative(builder);
            }
        });
        builder.show();
        return builder;
    }

    public interface DialogOnClickListener {

        public abstract void onClickPositive(Dialog dialog);

        public abstract void onClickNegative(Dialog dialog);

    }
/**
 *    lyj 2017-10-26 13:34
 */
public static Dialog showWarnGongniu(Context context, String title, String content, final DialogOnClickListener listener) {
    View view = LayoutInflater.from(context).inflate(R.layout.dialog_tip_loca, null);
    final AlertDialog builder = new AlertDialog.Builder(context).create();
    builder.setCancelable(false);
    builder.setView(view);
    TextView dialogDesc = (TextView) view.findViewById(R.id.dialog_description);
    Button btnPositive = (Button) view.findViewById(R.id.dialog_positive);
    dialogDesc.setText(content);
    btnPositive.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            listener.onClickPositive(builder);
        }
    });
    builder.show();
    return builder;
}

}
